package com.sdry.web.controller.jyy;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.sdry.model.jyy.Solid;
import com.sdry.model.jyy.SolidExample;
import com.sdry.model.jyy.SolidExample.Criteria;
import com.sdry.model.jyy.SolidPosition;
import com.sdry.model.llm.Team;
import com.sdry.model.llm.User;
import com.sdry.service.jyy.ShedudetailServise;
import com.sdry.service.jyy.SolidServise;
import com.sdry.utils.DateUtil;
import com.sdry.utils.ResponseUtil;
import com.sdry.web.controller.jyy.test.ReadTxt;
import com.sdry.web.controller.jyy.test.SerialComm;
import com.sdry.web.controller.jyy.test.SerialComm2;

/**
 * @ClassName:    [SolidController]   
 * @Description:  [固化 工位 Controller]   
 * @Author:       [jyy]   
 * @CreateDate:   [2018年10月12日 上午11:42:43]    
 * @Version:      [v1.0]
 */
@Controller
@RequestMapping("/solid")
public class SolidController {
	
	@Resource
	private SolidServise solidServise;
	
	@Resource
	private ShedudetailServise shedudetailServise;
	
	/**
	 * 去固化工位撤销页面
	 * @return
	 */
	@RequestMapping("/w4")
	public String toW4() {
		return "/jyy/w4back";
	}
	
	
	@RequestMapping("/getList")
	public void getList(Solid solid, HttpServletResponse response, 
			@RequestParam(value = "limit",required = false)int limit,
            @RequestParam(value = "page",required = false)int page) throws Exception {
		
		PageHelper.startPage(page, limit);
		
		SolidExample example = new SolidExample();
		Criteria createCriteria = example.createCriteria();
		
		if(StringUtil.isNotEmpty(solid.getStube())) {
			createCriteria.andStubeLike("%"+solid.getStube()+"%");
		}
		if(StringUtil.isNotEmpty(solid.getCremark())) {
			createCriteria.andCremarkLike("%"+solid.getCremark()+"%");
		}
		List<Solid> list = solidServise.selectByExample(example  );
		
		PageInfo<Solid> info = new PageInfo<Solid>(list);
    	
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code", 0);
        jsonObject.put("msg", "");
        jsonObject.put("count", info.getTotal());
        jsonObject.put("data", info.getList());
        ResponseUtil.write(response, jsonObject);
	}
	
	/**
	 * 添加
	 * @param response
	 * @param solid
	 * @throws Exception
	 */
	@RequestMapping("/save")
	public void save(HttpServletResponse response, Solid solid,HttpServletRequest request, HttpSession httpSession) throws Exception {
		
		String time = "";
		int insert = 0;
		//获取session中的人名
		User people = (User) request.getSession().getAttribute("currentUser");
		//与排产单对应的时间
		String today = people.getRemark3();
		
		//获取当前班组
		Team team = (Team) httpSession.getAttribute("team");
		//获取当前时间
		String dateFormat1 = DateUtil.dateFormat1();
		
		team.setRemark01(dateFormat1);
		if(team != null) {
			//根据当前时间  当前班组id 查询排产单号
			time = shedudetailServise.selectDaysheduTime(team);
		}
		//截取产品编码
		String tiaoma = solid.getStube();
		String substring = tiaoma.substring(3, 7);
		
		solid.setCremark3(substring);
		
		solid.setStartoperator(people.getUserName());
		solid.setCremark7(people.getUid()+"");
		
		solid.setCremark6("0");
		solid.setSplan(time);
		solid.setCremark2(today);
		solid.setCremark4(team.getTid()+"");
		solid.setCremark9(team.getCrew());
		//绑定成功后修改台车状态为1
		int affact = solidServise.editTcState1(solid.getCremark());
		if(affact > 0) {
			
			insert = solidServise.insert(solid);
		}
		
		ResponseUtil.write(response, insert);
	}
	
	/**
	 * 根据台车修改开始时间
	 * @param response
	 * @param solid
	 * @throws Exception 
	 */
	@RequestMapping("/edit2")
	public void edit2(HttpServletResponse response, Solid solid,HttpServletRequest request, HttpSession httpSession) throws Exception {
		
		int affact = 0;
		
		//获取session中的人名
		User people = (User) request.getSession().getAttribute("currentUser");
		//根据台车查询所有台车中的膜管
		SolidExample example = new SolidExample();
		Criteria createCriteria = example.createCriteria();
		if(solid.getCremark() != "" && solid.getCremark() != null) {
			createCriteria.andCremarkEqualTo(solid.getCremark());
		}
		
		List<Solid> list = solidServise.selectByExample(example );
		
		if(list.size() >0) {
			
			if(list.get(0).getStarttime() != null && list.get(0).getStarttime() != "") {
				//台车已经固化开始，请不要重复扫码
				affact = -2;
			}else {
				/*String time = "";
				//获取当前班组
				Team team = (Team) httpSession.getAttribute("team");
				//获取当前时间
				String dateFormat1 = DateUtil.dateFormat1();
				
				team.setRemark01(dateFormat1);
				if(team != null) {
					//根据当前时间  当前班组id 查询排产单号
					time = shedudetailServise.selectDaysheduTime(team);
				}*/
				
				for (Solid s: list) {
					Long id = s.getId();
					solid.setId(id);
					solid.setStarttime(DateUtil.dateFormat());
					solid.setStartoperator(people.getUserName());
					/*solid.setSplan(time);
					
					solid.setCremark4(team.getTid()+"");
					solid.setCremark9(team.getCrew());*/
					
					affact = solidServise.updateByPrimaryKeySelective(solid);
				}
			}
			
		}else {
			affact = -1;
		}
		
		ResponseUtil.write(response, affact);
	}
	/**
	 * 根据台车修改结束时间
	 * @param response
	 * @param solid
	 * @throws Exception 
	 */
	@RequestMapping("/edit")
	public void edit(HttpServletResponse response, Solid solid,HttpServletRequest request) throws Exception {
		
		int affact = 0;
		
		//获取session中的人名
		User people = (User) request.getSession().getAttribute("currentUser");
		
		//根据台车查询所有台车中的膜管
		SolidExample example = new SolidExample();
		Criteria createCriteria = example.createCriteria();
		if(solid.getCremark() != "" && solid.getCremark() != null) {
			createCriteria.andCremarkEqualTo(solid.getCremark());
		}
		
		List<Solid> list = solidServise.selectByExample(example );
		
		if(list.size() >0) {
			
			//先判断此台车开始了没有，开始了才能结束
			if(list.get(0).getStarttime() != "" && list.get(0).getStarttime() !=null) {
				for (Solid s: list) {
					Long id = s.getId();
					solid.setId(id);
					solid.setEndtime(DateUtil.dateFormat());
					solid.setEndoperator(people.getUserName());
					solid.setCremark("");
					affact = solidServise.updateByPrimaryKeySelective(solid);
				}
			}else {
				affact = -2;
			}
			
		}else {
			affact = -1;
		}
		
		ResponseUtil.write(response, affact);
	}
	
	/**
	 * 查询台车是否正在使用
	 * @param cremark
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/selectTc")
	public void selectTc(String cremark, HttpServletResponse response) throws Exception {
		int affact = 0;
		int total = 12;
		//1 根据台车条码查询数据库中是否存在此数据
		SolidExample example = new SolidExample();
		Criteria createCriteria = example.createCriteria();
		if(cremark != null && cremark != null) {
			createCriteria.andCremarkEqualTo(cremark);
		}
		
		List<Solid> list = solidServise.selectByExample(example );
		if(list.size() >0) {
			if(list.get(0).getStarttime() != "" && list.get(0).getStarttime() != null) {
				affact = -2;
			}else {
				if(list.size() == total) {
					affact = -1;
				}else {
					int count = list.size();
					affact = total - count;
				}
			}
		}else {
			int count = list.size();
			affact = total - count;
		}
		ResponseUtil.write(response, affact);
	}

	/**
	 * 查询膜管是否已固化
	 * @param stube
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/selectM")
	public void selectM(String stube, HttpServletResponse response) throws Exception {
		int affact = 0;
		
		int count = solidServise.selectCentrifugal(stube);
		
		if(count >0) {
			//1 根据台车条码查询数据库中是否存在此数据
			SolidExample example = new SolidExample();
			Criteria createCriteria = example.createCriteria();
			if(stube != null && stube != null) {
				createCriteria.andStubeEqualTo(stube);
			}
			createCriteria.andCremark6NotEqualTo("1");
			List<Solid> list = solidServise.selectByExample(example );
			
			if(list.size() > 0) {
				affact = 1;
			}
		}else {
			affact = -1;
		}
		
		ResponseUtil.write(response, affact);
	}
	
	/**
	 * 固化列表
	 * @throws Exception 
	 */
	@RequestMapping("/selectList")
	public void selectList(HttpServletResponse response) throws Exception {
		
		SolidExample example = new SolidExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andStarttimeIsNotNull();
		createCriteria.andCremarkIsNotNull();
		createCriteria.andEndtimeIsNull();
		List<Solid> list = solidServise.selectByExample2(example );
		
		if(list.size() >0) {
			for (Solid solid2 : list) {
				if(solid2 != null ) {
					
					SolidExample example2 = new SolidExample();
					Criteria createCriteria2 = example2.createCriteria();
					createCriteria2.andCremarkEqualTo(solid2.getCremark());
					List<Solid> list2 = solidServise.selectByExample(example2 );
					solid2.setCremark4(list2.size()+"");
				}
			}
		}
    	
        JSONArray jsonArray = JSONArray.fromObject( list ); 
        ResponseUtil.write(response, jsonArray);
		
	}
	/**
	 * 待切割  固化列表
	 * @throws Exception 
	 */
	@RequestMapping("/selectList2")
	public void selectList2(HttpServletResponse response) throws Exception {
		
		String now =DateUtil.dateFormat();
		
		SolidExample example = new SolidExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andStarttimeIsNotNull();
		createCriteria.andCremarkIsNotNull();
		List<Solid> list = solidServise.selectByExample2(example );
		if(list.size() >0) {
			
			/*JAVA中循环删除list中元素的方法总结
			1、for循环遍历list
			2、增强for循环
			3、iterator遍历
			（1）循环删除list中特定一个元素的，可以使用三种方式中的任意一种，但在使用中要注意上面分析的各个问题。
			（2）循环删除list中多个元素的，应该使用迭代器iterator方式。*/
			Iterator<Solid> it = list.iterator();
			while(it.hasNext()){
			    Solid solid2 = it.next();
			    String starttime = solid2.getStarttime();
				String cremark5 = solid2.getCremark5();
				String diff = diff(now,starttime);
				Integer valueOf = Integer.valueOf(diff);
				Integer valueOf2  = 0;
				if(cremark5 != null && cremark5 != "") {
					valueOf2 = Integer.valueOf(cremark5);
				}
				if( valueOf < valueOf2 ) {
					it.remove();
				}
			}
		}
		
		for (Solid solid2 : list) {
			SolidExample example2 = new SolidExample();
			Criteria createCriteria2 = example2.createCriteria();
			createCriteria2.andCremarkEqualTo(solid2.getCremark());
			List<Solid> list2 = solidServise.selectByExample(example2 );
			solid2.setCremark4(list2.size()+"");
			String s = "";
			String s2 = "";
			if(list2.size() <= 4) {
				
				for(int i = 0; i< list2.size(); i++) {
					if(i == 0) {
						s = list2.get(i).getStube();
					}else {
						s = s+","+list2.get(i).getStube();
					}
				}
				solid2.setCremark7(s);
				solid2.setCremark8("");
			}else {
				for(int i = 0; i< list2.size(); i++) {
					if(i == 0) {
						s = list2.get(i).getStube();
					}else {
						if(i <= 4) {
							s = s+","+list2.get(i).getStube();
						}else {
							if(i == 5) {
								s2 = s+","+list2.get(i).getStube();
							}else {
								s2 = s2+","+list2.get(i).getStube();
							}
						}
					}
				}
				solid2.setCremark7(s);
				solid2.setCremark8(s2);
			}
		}
		
		JSONArray jsonArray = JSONArray.fromObject( list ); 
        ResponseUtil.write(response, jsonArray);
		
	}
	
	public String diff(String now, String starttime) throws ParseException {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		
		Date now2 = format.parse(now);
		Date starttime2 = format.parse(starttime);
	    long nh = 1000 * 60 * 60;
	    // long ns = 1000;
	    // 获得两个时间的毫秒时间差异
	    long diff = now2.getTime() - starttime2.getTime();
	    // 计算差多少小时
	    long hour = diff / nh;
	    return hour+"";
	}
	
	/**
	 * 根据日期 和产品 编码 统计当日生产量
	 * @param date
	 * @param product
	 * @throws Exception 
	 */
	@RequestMapping("/selectActualNum")
	public void selectActualNum(HttpServletResponse response) throws Exception {
		Solid solid = new Solid();
		
		String time = "";
		
		Date date = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String format = dateFormat.format(date);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Integer now =Integer.parseInt(format.substring(11, 13));
		
		//判断当前时间是7：00之前，还是之后
		
		if(now > 7) {
			time = sdf.format(date);
		}else {
			Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 
			ca.setTime(date); //设置时间为当前时间
			ca.add(Calendar.DATE, -1);
			Date last = ca.getTime();
			time = sdf.format(last);
		}
		
		/*String startTime =format+" 00:00:0";
		String  endTime =format+" 23:59:59";
		
		solid.setCremark4(startTime);*/
		
		solid.setCremark5(time);
		
		int num = solidServise.selectActualNum(solid);
		ResponseUtil.write(response, num);
	}
	/**
	 * 根据日期 和产品 编码 统计当年生产量
	 * @param date
	 * @param product
	 * @throws Exception 
	 */
	@RequestMapping("/selectYearNum")
	public void selectYearNum(String product, HttpServletResponse response) throws Exception {
		Solid solid = new Solid();
		
		Date date = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
		String format = dateFormat.format(date);
		
		String startTime =format+"-01-01 00:00:0";
		String  endTime =format+"-12-31 23:59:59";
		
		if("PSH2-0960-T-01".endsWith(product)) {
			product = "0960";
		}else if("PSH2-0980-T-02".endsWith(product)) {
			product = "0980";
		}else if("PSH1-1060-B-03".endsWith(product)) {
			product = "1060";
		}else if("PSH1-1080-C-04".endsWith(product)) {
			product = "1080";
		}
		solid.setCremark3(product);
		solid.setCremark4(startTime);
		solid.setCremark5(endTime);
		
		int num = solidServise.selectYearNum(solid);
		ResponseUtil.write(response, num);
	}
	
	/**
	 * 根据台车条码 查询 此台车上所有的组件
	 * @param cremark 台车条码
	 * @param response 响应
	 */
	@RequestMapping("/selectDetail")
	public void selectDetail(String cremark, HttpServletResponse response,
			@RequestParam(value = "limit",required = false)int limit,
            @RequestParam(value = "page",required = false)int page) throws Exception {
		
		PageHelper.startPage(page, 5);
		
		SolidExample example = new SolidExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andCremarkEqualTo(cremark);
		List<Solid> list = solidServise.selectByExample(example );
		
		PageInfo<Solid> info = new PageInfo<Solid>(list);
    	
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("code", 0);
        jsonObject.put("msg", "");
        jsonObject.put("count", info.getTotal());
        jsonObject.put("data", info.getList());
        ResponseUtil.write(response, jsonObject);
	}
	
	@RequestMapping("/editcremark6")
	public void editcremark6(String code) {
		solidServise.editcremark6(code);
	}
	
	/**
	 * 删除（撤销绑定）
	 * @param ids
	 * @param response
	 * @throws Exception 
	 */
	@RequestMapping("/delete")
	public void delete(String ids, HttpServletResponse response) throws Exception {
		int affact = solidServise.deleteByPrimaryKeys(ids);
		ResponseUtil.write(response, affact);
	}
	
	/**
	 * 撤销开始固化
	 * @param response
	 * @param solid
	 * @throws Exception 
	 */
	@RequestMapping("/editStart")
	public void editStart(HttpServletResponse response, String ids) throws Exception {
		int affact = 0;
		String[] split = ids.split(",");
		for (String s : split) {
			Long id = Long.valueOf(s);
			affact = solidServise.updateStart(id);
		}
		
		ResponseUtil.write(response, affact);
	}
	
	/**
	 * 撤销结束固化
	 * @param response
	 * @param solid
	 * @throws Exception
	 */
	@RequestMapping("/editEnd")
	public void editEnd(HttpServletResponse response, String ids) throws Exception {
		
		int affact = 0;
		String[] split = ids.split(",");
		for (String s : split) {
			Long id = Long.valueOf(s);
			affact = solidServise.updateEnd(id);
		}
		ResponseUtil.write(response, affact);
	}
	
	/**
	 * 查询固化区当前台车总数
	 * @param response
	 * @throws Exception 
	 */
	@RequestMapping("/selectTcount")
	public void selectTcount(HttpServletResponse response) throws Exception {
		int count = solidServise.selectTcount();
		ResponseUtil.write(response, count);
	}
	
	/**
	 * 查询固化区当前组件总数
	 * @param response
	 * @throws Exception 
	 */
	@RequestMapping("/selectZcount")
	public void selectZcount(HttpServletResponse response) throws Exception {
		int count = solidServise.selectZcount();
		ResponseUtil.write(response, count);
	}
	
	/**
	 * 统计待切割台车总数
	 * @param response
	 * @throws Exception 
	 */
	@RequestMapping("/selectTcount2")
	public void selectTcount2(HttpServletResponse response) throws Exception {
		String now = DateUtil.dateFormat();
		
		SolidExample example = new SolidExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andStarttimeIsNotNull();
		createCriteria.andCremarkIsNotNull();
		List<Solid> list = solidServise.selectByExample2(example );
		if(list.size() >0) {
			
			/*JAVA中循环删除list中元素的方法总结
			1、for循环遍历list
			2、增强for循环
			3、iterator遍历
			（1）循环删除list中特定一个元素的，可以使用三种方式中的任意一种，但在使用中要注意上面分析的各个问题。
			（2）循环删除list中多个元素的，应该使用迭代器iterator方式。*/
			Iterator<Solid> it = list.iterator();
			while(it.hasNext()){
			    Solid solid2 = it.next();
			    if(solid2.getStarttime() != null && solid2.getStarttime() != "") {
			    	 String starttime = solid2.getStarttime();
						String cremark5 = solid2.getCremark5();
						String diff = diff(now,starttime);
						Integer valueOf = Integer.valueOf(diff);
						Integer valueOf2 = Integer.valueOf(cremark5);
						if( valueOf < valueOf2 ) {
							it.remove();
						}
			    }
			}
		}
		ResponseUtil.write(response, list.size());
	}
	
	/**
	 * 统计待切割组件总数
	 * @param response
	 * @throws Exception 
	 */
	@RequestMapping("/selectZcount2")
	public void selectZcount2(HttpServletResponse response) throws Exception {
		int count = 0;
		String now = DateUtil.dateFormat();
		
		SolidExample example = new SolidExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andStarttimeIsNotNull();
		createCriteria.andCremarkIsNotNull();
		List<Solid> list = solidServise.selectByExample2(example );
		if(list.size() >0) {
			
			/*JAVA中循环删除list中元素的方法总结
			1、for循环遍历list
			2、增强for循环
			3、iterator遍历
			（1）循环删除list中特定一个元素的，可以使用三种方式中的任意一种，但在使用中要注意上面分析的各个问题。
			（2）循环删除list中多个元素的，应该使用迭代器iterator方式。*/
			Iterator<Solid> it = list.iterator();
			while(it.hasNext()){
			    Solid solid2 = it.next();
			    String starttime = solid2.getStarttime();
				String cremark5 = solid2.getCremark5();
				String diff = diff(now,starttime);
				Integer valueOf = Integer.valueOf(diff);
				Integer valueOf2 = Integer.valueOf(cremark5);
				if( valueOf < valueOf2 ) {
					it.remove();
				}
			}
		}
		
		for (Solid solid2 : list) {
			SolidExample example2 = new SolidExample();
			Criteria createCriteria2 = example2.createCriteria();
			createCriteria2.andCremarkEqualTo(solid2.getCremark());
			List<Solid> list2 = solidServise.selectByExample(example2 );
			
			count = count+list2.size();
		}
		ResponseUtil.write(response, count);
	}
	
	/**
	 * 从time.properties文件中读取固化设定时间
	 * @throws Exception 
	 */
	@RequestMapping("/selectTime")
	public void selectTime(HttpServletResponse response) throws Exception {
	    	String pathname = ReadTxt.class.getClassLoader().getResource("time.properties").getPath();
	        //防止文件建立或读取失败，用catch捕捉错误并打印，也可以throw;
	        //不关闭文件会导致资源的泄露，读写文件都同理
	        //Java7的try-with-resources可以优雅关闭文件，异常时自动关闭文件；详细解读https://stackoverflow.com/a/12665271
	        try (FileReader reader = new FileReader(pathname);
	             BufferedReader br = new BufferedReader(reader) // 建立一个对象，它把文件内容转成计算机能读懂的语言
	        ) {
	            String line;
	            //网友推荐更加简洁的写法
	            while ((line = br.readLine()) != null) {
	                // 一次读入一行数据
	                System.out.println(line);
	                ResponseUtil.write(response, line);
	            }
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	}
	
	/**
	 * 向time.properties文件中写入固化设定时间
	 * @throws Exception 
	 */
	@RequestMapping("/setTime")
	public void setTime(String time, HttpServletResponse response) throws Exception {
		int affact = 0;
		
		String path = ReadTxt.class.getClassLoader().getResource("time.properties").getPath();
        try {
            File writeName = new File(path); // 相对路径，如果没有则要建立一个新的output.txt文件
            writeName.createNewFile(); // 创建新文件,有同名的文件的话直接覆盖
            try (FileWriter writer = new FileWriter(writeName);
                 BufferedWriter out = new BufferedWriter(writer)
            ) {
                out.write(time);
                out.flush(); // 把缓存区内容压入文件
                affact = 1;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        ResponseUtil.write(response, affact);
	}
	
	/**
	 * 查询未绑定的台车集合（状态为0的台车）
	 * @throws Exception 
	 */
	@RequestMapping("/selectWaitTc")
	public void selectWaitTc(HttpServletResponse response) throws Exception {
		List<String> list = solidServise.selectWaitTc();
		JSONArray jsonArray = JSONArray.fromObject( list ); 
        ResponseUtil.write(response, jsonArray);
	}
	
	/**
	 * 查询今日选择的排产单日期
	 * @throws Exception 
	 */
	@RequestMapping("/selectDaysheduTime")
	public void selectDaysheduTime(HttpServletResponse response, HttpSession httpSession) throws Exception {
		
		String time = "";
		
		//获取当前班组
		Team team = (Team) httpSession.getAttribute("team");
		if(team != null) {
			//根据当前时间  当前班组id 查询排产单号
			time = shedudetailServise.selectDaysheduTime(team);
		}
		
		ResponseUtil.write(response, time);
	}
	
	/**
	 * 根据配件id查询线边库批次号
	 * @param response
	 * @param id
	 * @throws Exception 
	 */
	@RequestMapping("/selectPcByPaid")
	public void selectPcByPaid(HttpServletResponse response, Long id) throws Exception {
		List<String> list = solidServise.selectPcByPaid(id);
		String s = "";
		if(list.size() > 0) {
			s = list.get(0);
		}
		ResponseUtil.write(response, s);
	}
	
	/**
	 * 查询固化区域里边的台车情况
	 * @throws Exception 
	 */
	@RequestMapping("/selectPosition")
	public void selectPosition(HttpServletResponse response) throws Exception {
		//查询固化区域位置表中的数据
		List<SolidPosition> list2= solidServise.selectPosition();
		
		if(list2.size() >0) {
			//根据台车条码，在固化表中查询此台车固化情况
			for (SolidPosition s : list2) {
				String tc = s.getTc();
				String now =DateUtil.dateFormat();
				
				SolidExample example = new SolidExample();
				Criteria createCriteria = example.createCriteria();
				createCriteria.andCremarkEqualTo(tc);
				List<Solid> list = solidServise.selectByExample2(example );
				if(list.size() >0) {
					
					for (Solid solid : list) {
						if(solid.getStarttime() != null && solid.getStarttime() != "") {
							String starttime = solid.getStarttime();
							String cremark5 = solid.getCremark5();
							String diff = diff(now,starttime);
							//实际固化时长
							Integer valueOf = Integer.valueOf(diff);
							//初始设定固化时长
							Integer valueOf2 = Integer.valueOf(cremark5);
							if( valueOf < valueOf2 ) {
								s.setRemark("no");
							}
						}
					}
				}
			}
		}
		
		JSONArray jsonArray = JSONArray.fromObject( list2 ); 
        ResponseUtil.write(response, jsonArray);
	}
	
}
